home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / sml_nj / 93src.lha / src / boot / makemos.sml < prev    next >
Encoding:
Text File  |  1993-01-27  |  1.9 KB  |  79 lines

  1. (* Copyright 1989 by AT&T Bell Laboratories *)
  2.  
  3. structure MakeMos = 
  4.   struct
  5.  
  6.     local
  7.       structure C = System.Code
  8.     in
  9.     fun makeMos {modName, mosDir} = let
  10.       type object = System.Unsafe.object
  11.       val applyCode : C.code -> unit -> ((object list -> object) * string list)
  12.         = C.apply
  13.  
  14.       val dict = ref ["Core"]
  15.       fun lookup s = let
  16.         fun f (s1::r) = s=s1 orelse f r
  17.           | f nil = false
  18.         in
  19.           f (!dict)
  20.         end
  21.       fun enter s = dict := s::(!dict)
  22.  
  23.       fun readfile s = let
  24.         val stream = open_in s
  25.         val file = C.inputCode (stream, (can_input stream))
  26.         in
  27.           close_in stream;
  28.           applyCode file
  29.         end
  30.  
  31.       val f = open_out (implode[mosDir, "/", modName, ".mos"])
  32.       val say = outputc f
  33.       fun getstruct s = if (lookup s)
  34.         then ()
  35.         else let
  36.           val s' = "mo/" ^ s ^ ".mo"
  37.           val _ = (say s'; say "\n")
  38.           val g = readfile s'
  39.           val (_, sl) = g ()
  40.           in
  41.             app getstruct sl;
  42.             enter s
  43.           end
  44.       in
  45.         output(std_out, modName ^ ".mos\n");
  46.         say "mo/CoreFunc.mo\n";
  47.         app getstruct ["Initial", "Loader", modName];
  48.         close_out f
  49.       end (* makeMos *)
  50.     end (* local *)
  51.  
  52.     val targets = [
  53.         "Vax", "M68", "Sparc", "MipsLittle", "MipsBig", 
  54.         "RS6000", "I386"
  55.       ]
  56.  
  57.     fun makeMosForTarget {mosDir} target = (
  58.       makeMos {modName = "Int"^target, mosDir = mosDir};
  59.       makeMos {modName = "Int"^target^"D", mosDir = mosDir};
  60.       makeMos {modName = "Comp"^target, mosDir = mosDir})
  61.  
  62.     fun makePervMos {mosDir} = let
  63.       val f = open_out (mosDir ^ "/Perv.mos")
  64.       in
  65.         output (std_out, "Perv.mos");
  66.         output (f, "mo/CoreFunc.mo\n");
  67.         output (f, "mo/Math.mo\n");
  68.         output (f, "mo/Initial.mo\n");
  69.         close_out f
  70.       end
  71.  
  72.     fun makeAllMos {mosDir} = (
  73.       makePervMos {mosDir = mosDir};
  74.       makeMos {modName = "IntNull", mosDir = mosDir};
  75.       makeMos {modName = "IntNullD", mosDir = mosDir};
  76.       app (makeMosForTarget {mosDir = mosDir}) targets)
  77.  
  78.   end; (* MakeMos *)
  79.